<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>显示当前的时分秒</title>
  </head>

  <body>

  </body>
  <script>
    //var now = new Date();
    var getNow = function () {
      var now = new Date();
      var h = now.getHours();
      h = h < 10 ? "0" + h : h
      var m = now.getMinutes();
      m = m < 10 ? "0" + m : m;
      var s = now.getSeconds();
      s = s < 10 ? "0" + s : s;
      document.write("现在时间是" + h + ":" + m + ":" + s + "<br/>");
    }
    //getNow()
    setInterval(function () {
      getNow()
    }, 1000)
  </script>

</html>